// 获取全局应用程序实例对象
const app = getApp();
const {get,post} = app.utils.request;
const {merchant_list} = app.utils.config;

var url = "http://www.imooc.com/course/ajaxlist"; 
var page = 0;
var page_size = 5;
var sort = "last";
var is_easy = 0;
var lange_id = 0;
var pos_id = 0;
var unlearn = 0;


// 请求数据
var loadMore = function(that) {
	that.setData({
		hidden: false
	});
	post({path: `${merchant_list}`},{merchant_id:1})
	.then((res)=>{
		var list = that.data.list;
		for (var i = 0; i < res.data.list.length; i++) {
			list.push(res.data.list[i]);
		}
		that.setData({
			list: list
		});
		page++;
		that.setData({
			hidden: true
		});
	});
}

// 组件基础代码
Component({
	behaviors: [],
	properties: {},
	data: {
		hidden: true,
		list: [],
		scrollTop: 0,
		scrollHeight: 0
	},
	attached: function() {
		console.log('加载列表')
		var that = this;
		wx.getSystemInfo({
			success: function(res) {
				that.setData({
					scrollHeight: res.windowHeight - 210
				});
			}
		});
		loadMore(that);
	},
	methods: {
		//页面滑动到底部
		bindDownLoad: function() {
			var that = this;
			loadMore(that);
			console.log("lower");
		},
		scroll: function(event) {
			//该方法绑定了页面滚动时的事件，我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。
			this.setData({
				scrollTop: event.detail.scrollTop
			});
		},
		topLoad: function(event) {
			//   该方法绑定了页面滑动到顶部的事件，然后做上拉刷新
			// page = 0;
			// this.setData({
			// 	list: [],
			// 	scrollTop: 0
			// });
			// loadMore(this);
			// console.log("lower");
		}
	}
});